<?

if ($c = stack('name')) {
	
	$_id_data		= D_MB_DATA;			//	meta id value
	$_id_meta		= D_MB_META;			//	meta id value

	$_lang = context('lang');
	$_id = $DATA['components'][$c]['id'];


	$mckey = "cpn.recent.$_id.$_lang";
	
//	if (MC && ($t = $GLOBALS['mc']->get(MC_PREFIX.".cpn.recent.$_id.$_lang"))) {

	if ($t = mc($mckey)) {
		$DATA['components'][$c]['data'] = $t;
	} else {		
	

	$s = component_settings($c);

	if (($p = trim($s['hide_parametric'])) && param($p)) {
		unset($DATA['components'][$c]);
		unstack();
		return false;
	}

	if ($_id_component = (int)$s['catalogs']) {
		
			$_table = 'data, data meta';
		
			$_crit = "data.id_data=$_id_data AND data.id_parent=$_id_component AND ".dbAndL('data.attr', AA_VISIBLE)." AND meta.id_data=$_id_meta AND meta.id_parent=data.id AND meta.name='title' AND meta.assoc='$_lang' AND meta.value IS NOT NULL";
		
		$DATA['components'][$c]['data'] = array_mark_bounds(datafetch_array('db_list', array(
				'select' => 'data.*',
				'table' => tb($_table),
			'where' => $_crit,	
				'order' => 'data.id_index '.($s['order'] ? 'DESC' : 'ASC'), 
			'limit' => (int)$s['num'],
			'index' => 'id' )));

			$setts = datafetch_array('meta', D_MB_SETTINGS, $_id_component);

			$t = datafetch_array('loadmeta', $_id_meta, 
				array('parent' => array_keys($DATA['components'][$c]['data']), 'assoc' => $_lang, 'getclob' => true, 'source' => true));
				
			foreach($t as $v)
				$DATA['components'][$c]['data'][$v['id_parent']][$v['name']] = $v['value'];
	
		foreach($DATA['components'][$c]['data'] as $k => $v) {
			$DATA['components'][$c]['data'][$k]['date'] = format_simple_date($v['date_create']);
			$DATA['components'][$c]['data'][$k]['tn'] = checkImage(FP_UPLOAD_PATH.$setts['path'], $k);
		}

	}
	
		mcSet($mckey, $DATA['components'][$c]['data'], MC_EXPIRE - mt_rand(2*60, 7*60));
		
	}
	unstack();
}
